package com.suarte.webapp.action;

import com.suarte.core.Company;
import com.suarte.core.Contact;
import com.suarte.core.QuotationStatus;
import com.suarte.core.service.CompanyManager;
import com.suarte.core.service.ContactManager;
import com.suarte.core.service.QuotationManager;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @date   Dec 20, 2010
 * @author Ggutierrez
 */
public class QuotationList extends BasePage implements Serializable {

    private QuotationManager quotationManager;
    private CompanyManager companyManager;
    private ContactManager contactManager;
    private Long id;
    private String description;
    private Date date;
    private List quotations;
    private List<Company> companies;
    private Company company;
    private List<Contact> contacts;
    private Contact contact;
    private String stStatus;

    public void setQuotationManager(QuotationManager quotationManager) {
        this.quotationManager = quotationManager;
    }

    public void setCompanyManager(CompanyManager companyManager) {
        this.companyManager = companyManager;
    }

    public void setContactManager(ContactManager contactManager) {
        this.contactManager = contactManager;
    }

    public QuotationList() {
        setSortColumn("id"); // sets the default sort column
    }

    public String execute() {
        QuotationStatus status = stStatus != null ? QuotationStatus.valueOf(stStatus) : null;
        quotations = sort(quotationManager.findQuotations(id, description, date, company, contact, status));

        return "list";
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List getQuotations() {
        QuotationStatus status = stStatus != null ? QuotationStatus.valueOf(stStatus) : null;
        if (contact != null || description != null || id != null || company != null) {
            quotations = sort(quotationManager.findQuotations(id, description, date, company, contact, status));
        }
        if (quotations != null) {
            return sort(quotations);
        } else {
            return quotations;
        }
    }

    public void setQuotations(List quotations) {
        this.quotations = quotations;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public List<Company> getCompanies() {
        companies = companyManager.findCompanies();
        return companies;
    }

    public void setCompanies(List<Company> companies) {
        this.companies = companies;
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public List<Contact> getContacts() {
        //contacts = contactManager.findContacts();
        return contacts;
    }

    public void setContacts(List<Contact> contacts) {
        this.contacts = contacts;
    }

    public Contact getContact() {
        return contact;
    }

    public void setContact(Contact contact) {
        this.contact = contact;
    }

    public String getStStatus() {
        return stStatus;
    }

    public void setStStatus(String stStatus) {
        this.stStatus = stStatus;
    }
}
